import request from '@/utils/request';
const apiKey = import.meta.env.VITE_CHAT_API_KEY;
export const sendQuestionService = async (
  messages: Array<{
    content: string;
    role: 'user' | 'assistant';
  }>,
  onChunk: (chunk: string) => void,
  signal?: AbortSignal
) => {
  const data = {
    url: '/chat/completions',
    method: 'post',
    data: {
      // model: 'deepseek-ai/DeepSeek-V2.5',
      model: 'Qwen/QwQ-32B',
      // model: 'deepseek-ai/DeepSeek-R1',
      stream: true,
      max_tokens: 2048,
      temperature: 0.7,
      top_p: 0.7,
      top_k: 50,
      frequency_penalty: 0.5,
      n: 1,
      messages: messages,
    },
    headers: {
      authorization: `Bearer ${apiKey}`,
    },
  };
  if (signal) {
    data.signal = signal;
  }
  request.requestSSE(
    data,
    (chunk) => {
      typeof onChunk === 'function' && onChunk(chunk);
      // answer.value += chunk
    },
    (error) => {
      console.error('Stream error:', error);
    }
  );
};
